package cj.web.admin.dao;
/*
 *  
 *  
*/
import java.util.List;
import java.util.Map;

import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.ReturnGeneratedKeys;
import net.paoding.rose.jade.annotation.SQL;
import net.paoding.rose.jade.annotation.SQLParam;
import cj.web.admin.domain.SurveyDepotItem;

/**
 * 
 * @author 
 *
 */
@DAO
public interface SurveyDepotItemDAO{
	
	@SQL("SELECT * FROM SurveyDepotItem WHERE deleteFlag=1 AND subjectDepotId=:t.subjectDepotId ORDER BY orderNum LIMIT :t.start,:t.length ")
    List<Map> query(@SQLParam("t") SurveyDepotItem voteItem);
	
	@SQL("SELECT count(*) FROM SurveyDepotItem WHERE deleteFlag=1 AND subjectDepotId=:t.subjectDepotId ")
    int querysize(@SQLParam("t") SurveyDepotItem voteItem);
    
    @SQL("select * from SurveyDepotItem where id=:1")
    SurveyDepotItem queryById(int id);
    
    @ReturnGeneratedKeys
    @SQL("INSERT INTO SurveyDepotItem (surveyDepotId,subjectDepotId,item,deleteFlag,createUser,createAt,updateUser,updateAt,orderNum,answer) VALUES (:1,:2,:3,1,:4,now(),:4,now(),:5,:6)")
    int create(int surveyDepotId, int subjectDepotId, String item, String user, int orderNum, int answer);
	
	@SQL("UPDATE SurveyDepotItem SET item=:2,updateUser=:3,updateAt=now(),orderNum=:4,answer=:5,deleteFlag=1 WHERE id=:1")
	void update(int itemId, String item, String user, int orderNum, int answer);
	
    @SQL("UPDATE SurveyDepotItem SET deleteFlag=0 WHERE id=:1")
    void deleteById(int id);
    
    @SQL("UPDATE SurveyDepotItem SET deleteFlag=0 WHERE subjectDepotId=:1")
    void deleteBySubId(int subjectId);
    
    @SQL("SELECT * FROM SurveyDepotItem WHERE deleteFlag=1 AND subjectDepotId=:1 order by orderNum")
	List<Map> queryBySubjectId(int subjectDepotId);
    
    @SQL("SELECT id FROM SurveyDepotItem WHERE deleteFlag=1 AND subjectDepotId=:1 AND answer=1 ")
	List<Integer> queryIdBySubjectId(int subjectDepotId);
}